summaryrefslogtreecommitdiff
path: root/src/packedintarray.h
blob: 953492b678edf8c19ce5ba6b9f48a41cca77feca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef PACKED_INT_ARRAY_H
#define PACKED_INT_ARRAY_H

#include <bu/string.h>

class PackedIntArray
{
public:
    typedef uint_fast8_t Unit;
    PackedIntArray( Unit iBitWidth );
    PackedIntArray( Unit iBitWidth, int iCapacity );
    virtual ~PackedIntArray();

    void append( Unit i );
    Unit operator[]( int idx ) const { return get( idx ); }
    Unit get( int idx ) const;
    Unit set( int idx, Unit i );
    int getSize() const { return iCount; }

    Bu::String toBitString() const;
    Bu::String toString() const;

private:
    void checkCapacity();

private:
    typedef uint_fast32_t Store;
    Unit iBitWidth;
    Store *aData;
    int iCapacity;
    int iCount;
    int iMaxSpan;
    Unit uMask;
};

#endif